#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: ix-motd
# REQUIRE: FILESYSTEMS
# BEFORE: motd

. /etc/rc.subr

generate_motd()
{
	local motd
	cp /conf/base/etc/motd /etc/motd
	RO_FREENAS_CONFIG=$(ro_sqlite ${name} 2> /tmp/${name}.fail && rm /tmp/${name}.fail)
	trap 'rm -f ${RO_FREENAS_CONFIG}' EXIT
	motd=$(${FREENAS_SQLITE_CMD} ${RO_FREENAS_CONFIG} "SELECT adv_motd FROM system_advanced ORDER BY id DESC LIMIT 1")
	if [ -n "${motd}" ]; then
		echo "${motd}" >> /etc/motd
	fi
}

name="ix-motd"
start_cmd='generate_motd'
stop_cmd=':'

load_rc_config $name
run_rc_command "$1"
